namespace DotNetNuke.Services.Exceptions
{
    using DotNetNuke.Entities.Portals;
    using DotNetNuke.Entities.Users;
    using DotNetNuke.Services.Localization;
    using DotNetNuke.UI.Skins;
    using DotNetNuke.UI.Skins.Controls;
    using System;
    using System.Collections.Generic;
    using System.Web.UI;

    public class ErrorContainer : Control
    {
        private static List<WeakReference> __ENCList = new List<WeakReference>();
        private ModuleMessage _Container;

        public ErrorContainer(string strError)
        {
            List<WeakReference> refObjectHelperL0 = __ENCList;
            lock (refObjectHelperL0)
            {
                __ENCList.Add(new WeakReference(this));
            }
            this.Container = this.FormatException(strError);
        }

        public ErrorContainer(string strError, Exception exc)
        {
            List<WeakReference> refObjectHelperL0 = __ENCList;
            lock (refObjectHelperL0)
            {
                __ENCList.Add(new WeakReference(this));
            }
            this.Container = this.FormatException(strError, exc);
        }

        public ErrorContainer(PortalSettings _PortalSettings, string strError, Exception exc)
        {
            List<WeakReference> refObjectHelperL0 = __ENCList;
            lock (refObjectHelperL0)
            {
                __ENCList.Add(new WeakReference(this));
            }
            if (UserController.GetCurrentUserInfo().IsSuperUser)
            {
                this.Container = this.FormatException(strError, exc);
            }
            else
            {
                this.Container = this.FormatException(strError);
            }
        }

        private ModuleMessage FormatException(string strError)
        {
            return Skin.GetModuleMessageControl(DotNetNuke.Services.Localization.Localization.GetString("ErrorOccurred"), strError, ModuleMessage.ModuleMessageType.RedError);
        }

        private ModuleMessage FormatException(string strError, Exception exc)
        {
            if (exc != null)
            {
                return Skin.GetModuleMessageControl(strError, exc.ToString(), ModuleMessage.ModuleMessageType.RedError);
            }
            return Skin.GetModuleMessageControl(DotNetNuke.Services.Localization.Localization.GetString("ErrorOccurred"), strError, ModuleMessage.ModuleMessageType.RedError);
        }

        public ModuleMessage Container
        {
            get
            {
                return this._Container;
            }
            set
            {
                this._Container = value;
            }
        }
    }
}

